// 检查是否登录
function isLogin() {
    if (localStorage.getItem("is") == null || JSON.parse(localStorage.getItem("is")).isLogin !== "true") {
        window.location.href = '../html/login.html';
        alert("当前未登录，将退出主页");
    }
}

// 登出
function confirmLogout() {
    let r = confirm("确定退出当前登录？");
    if (r === true) setLogout();
}

function setLogout() {
    let username = JSON.parse(localStorage.getItem("is")).username;
    let is = JSON.stringify({"username": username, "isLogin": "false"})
    localStorage.removeItem("is");
    localStorage.setItem("is", is);
    isLogin();
}

// 设置
function showSetting() {
    document.getElementById("setting-list").style.display = "block";
    document.getElementById("setting").innerHTML = "关闭设置";
    document.getElementById("setting").href = "javascript:hideSetting()";
}

function hideSetting() {
    document.getElementById("setting-list").style.display = "none";
    document.getElementById("setting").innerHTML = "设&nbsp;&nbsp;&nbsp;&nbsp;置";
    document.getElementById("setting").href = "javascript:showSetting()";
}

// 注销
function confirmClose() {
    let r = confirm("确定注销账号？\n您可能将永远失去此账号的信息！");
    if (r === true) window.location.href = "../html/close-account.html";
}